Alphabetical pagination

Alphabetical pagination

am 14.07.2009 21:38:23 von tmiller

I am trying to make a page that displays a-z like a b c d e etc as links
then when you click open one it reloads itself and shows only the query
results that go with that letter...i'm not getting it....I get a page that
says ARRAY over and over...

What I have so far:

if(!isset($_SESSION['RestaurantList']))

{
// List not grabbed yet, so run
query and store in $_SESSION

$sql =3D "SELECT
DISTINCT name FROM restaurants GROUP BY name DESC";

$result =3D mysql_query($sql) or die(mysql_error()) ;

$count =3D mysql_num_rows($result);

echo $count;
=20

while($row =3D mysql_fetch_array($result)) {

=20

$name=3Darray($row['name'],0,1);

//$name =3D array('name');

echo " href=3D\"page.php?name=3D" .$name. "\"> $name\n";

}=20
=20

}

=20

$alphabet =3D range('A', 'Z');

foreach ($alphabet as $letter) {

echo '
.. '?letter=3D' . $letter . '">' . $letter . '
';

}=20
=20

=20

=20

?>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 14.07.2009 22:27:18 von Dan Shirah

--000e0cd340f0dc2161046eb04335
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

>
> I am trying to make a page that displays a-z like a b c d e etc as links
> then when you click open one it reloads itself and shows only the query
> results that go with that letter...i'm not getting it....I get a page that
> says ARRAY over and over...
>
> What I have so far:
> >
> if(!isset($_SESSION['RestaurantList']))
>
> {
> // List not grabbed yet, so run
> query and store in $_SESSION
>
> $sql = "SELECT
> DISTINCT name FROM restaurants GROUP BY name DESC";
>
> $result = mysql_query($sql) or die(mysql_error()) ;
>
> $count = mysql_num_rows($result);
>
> echo $count;
>
>
> while($row = mysql_fetch_array($result)) {
>
>
>
> $name=array($row['name'],0,1);
>
> //$name = array('name');
>
> echo " > href=\"page.php?name=" .$name. "\"> $name\n";
>
> }
>
>
> }
>
>
>
> $alphabet = range('A', 'Z');
>
> foreach ($alphabet as $letter) {
>
> echo '' . $letter . '';
>
> }
>
>
>
>
>
>
> ?>
>

Well, are you opposed to using Javascript?

//javascript function


//You could make a hidden form field to store the value of the letter
selected.





//Perform your query and search only for the letter if it isn't blank.
$selected_letter = $_POST['letter'];
if ($select_letter != "") {
$sql = "SELECT DISTINCT name FROM restaurants WHERE name LIKE
'$letter%' GROUP BY name DESC";
}
?>
//Print out all your letters
$alphabet = range('A', 'Z');

foreach ($alphabet as $letter) {
?>
//Have the links call a javascript function that updates the letter selected
and resubmits the form to perform your new query

}
?>

Something like that. I haven't tested any of that code just typed it up real
quick to give you an idea of one way to possibly do it.

Hope that helps.

Dan

--000e0cd340f0dc2161046eb04335--

Re: Alphabetical pagination

am 14.07.2009 22:44:14 von Andrew Ballard

On Tue, Jul 14, 2009 at 3:38 PM, Miller,
Terion wrote:
> I am trying to make a page that displays a-z like a b c d e etc as links
> then when you click open one it reloads itself and shows only the query
> results that go with that letter...i'm not getting it....I get a page tha=
t
> says ARRAY over and over...
>
> What I have so far:
>                     =C2=
=A0       >
> if(!isset($_SESSION['RestaurantList']))
>
> {
>                     =C2=
=A0                // List not grab=
bed yet, so run
> query and store in $_SESSION
>
>                     =C2=
=A0                     =
             $sql =3D "SELECT
> DISTINCT name FROM restaurants  GROUP BY name DESC";
>
> $result =3D mysql_query($sql) or die(mysql_error()) ;
>
> $count =3D mysql_num_rows($result);
>
> echo $count;
>
>
> while($row =3D mysql_fetch_array($result)) {
>
>
>
> $name=3Darray($row['name'],0,1);




Why are you setting the value of $name to an array? If you try to echo
$name after this statement (as you are below), PHP will echo the word
"Array".



>
> //$name =3D array('name');
>
>                     =C2=
=A0                     =
             echo " > href=3D\"page.php?name=3D" .$name. "\"> $name\n";
>
> }
>
>
>                     =C2=
=A0                     =
                    =C2=
=A0    }
>
>
>
> $alphabet =3D range('A', 'Z');
>
> foreach ($alphabet as $letter) {
>
> echo ' >
> . '?letter=3D' . $letter . '">' . $letter . '
';
>
> }
>
>
>
>
>
>
> ?>

If the list of restaurants is very long, I wouldn't store it in a
session variable. It is the same for every person who visits your
site, so there is little use storing separate redundant copies in
session scope where it will needlessly fill up disk space and/or
memory.

As far as the query is concerned, you could do this:


$index_letter =3D $_GET['letter'];

if (preg_match('/^[A-Za-z]$/', $index_letter)) {

$sql =3D "SELECT DISTINCT name FROM restaurants WHERE name LIKE
'$index_letter%' GROUP BY name DESC";

//....
?>

I would also consider whether you really need the keyword DISTINCT in
the query. In a properly normalized table, name should probably
already be distinct (and constrained by a UNIQUE index on that
column).

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 07:35:04 von List Manager

Andrew Ballard wrote:
> On Tue, Jul 14, 2009 at 3:38 PM, Miller,
> Terion wrote:
>> I am trying to make a page that displays a-z like a b c d e etc as links
>> then when you click open one it reloads itself and shows only the query
>> results that go with that letter...i'm not getting it....I get a page that
>> says ARRAY over and over...
>>
>> What I have so far:
>> >>
>> if(!isset($_SESSION['RestaurantList']))
>>
>> {
>> // List not grabbed yet, so run
>> query and store in $_SESSION
>>
>> $sql = "SELECT
>> DISTINCT name FROM restaurants GROUP BY name DESC";
>>
>> $result = mysql_query($sql) or die(mysql_error()) ;
>>
>> $count = mysql_num_rows($result);
>>
>> echo $count;
>>
>>
>> while($row = mysql_fetch_array($result)) {
>>
>>
>>
>> $name=array($row['name'],0,1);
>
>
>
>
> Why are you setting the value of $name to an array? If you try to echo
> $name after this statement (as you are below), PHP will echo the word
> "Array".
>
>
>
>> //$name = array('name');
>>
>> echo " >> href=\"page.php?name=" .$name. "\"> $name\n";
>>
>> }
>>
>>
>> }
>>
>>
>>
>> $alphabet = range('A', 'Z');
>>
>> foreach ($alphabet as $letter) {
>>
>> echo '' . $letter . '';
>>
>> }
>>
>>
>>
>>
>>
>>
>> ?>
>
> If the list of restaurants is very long, I wouldn't store it in a
> session variable. It is the same for every person who visits your
> site, so there is little use storing separate redundant copies in
> session scope where it will needlessly fill up disk space and/or
> memory.
>
> As far as the query is concerned, you could do this:
>
> >
> $index_letter = $_GET['letter'];
>
> if (preg_match('/^[A-Za-z]$/', $index_letter)) {
>
> $sql = "SELECT DISTINCT name FROM restaurants WHERE name LIKE
> '$index_letter%' GROUP BY name DESC";
>
> //....
> ?>
>
> I would also consider whether you really need the keyword DISTINCT in
> the query. In a properly normalized table, name should probably
> already be distinct (and constrained by a UNIQUE index on that
> column).
>
> Andrew
>

Also, since this is MySQL, you need to make sure you make it non case-sensitive by using ILIKE instead of LIKE in that
SELECT statement.

$sql = "SELECT DISTINCT name FROM restaurants WHERE name iLIKE '$index_letter%' GROUP BY name DESC";

--
Jim Lucas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 09:28:18 von Ashley Sheridan

On Wednesday 15 July 2009 06:35:04 Jim Lucas wrote:
> Andrew Ballard wrote:
> > On Tue, Jul 14, 2009 at 3:38 PM, Miller,
> >
> > Terion wrote:
> >> I am trying to make a page that displays a-z like a b c d e etc as links
> >> then when you click open one it reloads itself and shows only the query
> >> results that go with that letter...i'm not getting it....I get a page
> >> that says ARRAY over and over...
> >>
> >> What I have so far:
> >> > >>
> >> if(!isset($_SESSION['RestaurantList']))
> >>
> >> {
> >> // List not grabbed yet, so run
> >> query and store in $_SESSION
> >>
> >> $sql = "SELECT
> >> DISTINCT name FROM restaurants GROUP BY name DESC";
> >>
> >> $result = mysql_query($sql) or die(mysql_error()) ;
> >>
> >> $count = mysql_num_rows($result);
> >>
> >> echo $count;
> >>
> >>
> >> while($row = mysql_fetch_array($result)) {
> >>
> >>
> >>
> >> $name=array($row['name'],0,1);
> >
> > Why are you setting the value of $name to an array? If you try to echo
> > $name after this statement (as you are below), PHP will echo the word
> > "Array".
> >
> >> //$name = array('name');
> >>
> >> echo " > >> href=\"page.php?name=" .$name. "\"> $name\n";
> >>
> >> }
> >>
> >>
> >> }
> >>
> >>
> >>
> >> $alphabet = range('A', 'Z');
> >>
> >> foreach ($alphabet as $letter) {
> >>
> >> echo '' . $letter . '';
> >>
> >> }
> >>
> >>
> >>
> >>
> >>
> >>
> >> ?>
> >
> > If the list of restaurants is very long, I wouldn't store it in a
> > session variable. It is the same for every person who visits your
> > site, so there is little use storing separate redundant copies in
> > session scope where it will needlessly fill up disk space and/or
> > memory.
> >
> > As far as the query is concerned, you could do this:
> >
> > > >
> > $index_letter = $_GET['letter'];
> >
> > if (preg_match('/^[A-Za-z]$/', $index_letter)) {
> >
> > $sql = "SELECT DISTINCT name FROM restaurants WHERE name LIKE
> > '$index_letter%' GROUP BY name DESC";
> >
> > //....
> > ?>
> >
> > I would also consider whether you really need the keyword DISTINCT in
> > the query. In a properly normalized table, name should probably
> > already be distinct (and constrained by a UNIQUE index on that
> > column).
> >
> > Andrew
>
> Also, since this is MySQL, you need to make sure you make it non
> case-sensitive by using ILIKE instead of LIKE in that SELECT statement.
>
> $sql = "SELECT DISTINCT name FROM restaurants WHERE name iLIKE
> '$index_letter%' GROUP BY name DESC";
>
> --
> Jim Lucas

You only have to use that if your character set is not latin1 or
latin1_swedish_ci. Using LIKE on those character sets is case-insensitive
too.

--
Thanks,
Ash
http://www.ashleysheridan.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 14:52:40 von Andrew Ballard

On Wed, Jul 15, 2009 at 3:28 AM, Ashley
Sheridan wrote:
> On Wednesday 15 July 2009 06:35:04 Jim Lucas wrote:
>> Andrew Ballard wrote:
>> > On Tue, Jul 14, 2009 at 3:38 PM, Miller,
>> >
>> > Terion wrote:
>> >> I am trying to make a page that displays a-z like a b c d e etc as li=
nks
>> >> then when you click open one it reloads itself and shows only the que=
ry
>> >> results that go with that letter...i'm not getting it....I get a page
>> >> that says ARRAY over and over...
>> >>
>> >> What I have so far:
>> >>                    =
        >> >>
>> >> if(!isset($_SESSION['RestaurantList']))
>> >>
>> >> {
>> >>                    =
                 // List not =
grabbed yet, so run
>> >> query and store in $_SESSION
>> >>
>> >>                    =
                    =C2=
=A0              $sql =3D "SELECT
>> >> DISTINCT name FROM restaurants  GROUP BY name DESC";
>> >>
>> >> $result =3D mysql_query($sql) or die(mysql_error()) ;
>> >>
>> >> $count =3D mysql_num_rows($result);
>> >>
>> >> echo $count;
>> >>
>> >>
>> >> while($row =3D mysql_fetch_array($result)) {
>> >>
>> >>
>> >>
>> >> $name=3Darray($row['name'],0,1);
>> >
>> > Why are you setting the value of $name to an array? If you try to echo
>> > $name after this statement (as you are below), PHP will echo the word
>> > "Array".
>> >
>> >> //$name =3D array('name');
>> >>
>> >>                    =
                    =C2=
=A0              echo " >> >> href=3D\"page.php?name=3D" .$name. "\"> $name\n";
>> >>
>> >> }
>> >>
>> >>
>> >>                    =
                    =C2=
=A0                     =
     }
>> >>
>> >>
>> >>
>> >> $alphabet =3D range('A', 'Z');
>> >>
>> >> foreach ($alphabet as $letter) {
>> >>
>> >> echo ' >> >>
>> >> . '?letter=3D' . $letter . '">' . $letter . '
';
>> >>
>> >> }
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> ?>
>> >
>> > If the list of restaurants is very long, I wouldn't store it in a
>> > session variable. It is the same for every person who visits your
>> > site, so there is little use storing separate redundant copies in
>> > session scope where it will needlessly fill up disk space and/or
>> > memory.
>> >
>> > As far as the query is concerned, you could do this:
>> >
>> > >> >
>> > $index_letter =3D $_GET['letter'];
>> >
>> > if (preg_match('/^[A-Za-z]$/', $index_letter)) {
>> >
>> >     $sql =3D "SELECT DISTINCT name FROM restaurants WHERE na=
me LIKE
>> > '$index_letter%' GROUP BY name DESC";
>> >
>> > //....
>> > ?>
>> >
>> > I would also consider whether you really need the keyword DISTINCT in
>> > the query. In a properly normalized table, name should probably
>> > already be distinct (and constrained by a UNIQUE index on that
>> > column).
>> >
>> > Andrew
>>
>> Also, since this is MySQL, you need to make sure you make it non
>> case-sensitive by using ILIKE instead of LIKE in that SELECT statement.
>>
>> $sql =3D "SELECT DISTINCT name FROM restaurants WHERE name iLIKE
>> '$index_letter%' GROUP BY name DESC";
>>
>> --
>> Jim Lucas
>
> You only have to use that if your character set is not latin1 or
> latin1_swedish_ci. Using LIKE on those character sets is case-insensitive
> too.
>
> --
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>

.... or any of the other *_ci character set collations. ;-) I generally
use utf8_unicode_ci in MySQL.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 17:21:22 von TedD

At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
>I am trying to make a page that displays a-z like a b c d e etc as links
>then when you click open one it reloads itself and shows only the query
>results that go with that letter...i'm not getting it....I get a page that
>says ARRAY over and over...
>
>What I have so far:
-snip-

Why not have MySQL sort the data instead of using php?

For example (from memory -- use with caution)

SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1

Then just change the offset to go up and down the list.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 17:29:01 von tmiller

On 7/15/09 10:30 AM, "Ashley Sheridan" wrote:

On Wednesday 15 July 2009 16:21:22 tedd wrote:
> At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
> >I am trying to make a page that displays a-z like a b c d e etc as links
> >then when you click open one it reloads itself and shows only the query
> >results that go with that letter...i'm not getting it....I get a page th=
at
> >says ARRAY over and over...
> >
> >What I have so far:
>
> -snip-
>
> Why not have MySQL sort the data instead of using php?
>
> For example (from memory -- use with caution)
>
> SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1
>
> Then just change the offset to go up and down the list.
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com

You could do what Tedd suggested, but use MySQL to actually limit the resul=
ts
it returns you by using a like clause, i.e. WHERE `somefield` LIKE 'a%'.

*ducks to avoid people throwing things at him. I know it's slow!*

--
Thanks,
Ash
http://www.ashleysheridan.co.uk


Hi all thanks for all the suggestions, I really had no idea this was going =
to be so difficult..I am a bit closer..well I have the alphabet showing up =
now I just have to get it to actually pull results..LMAO
Here is my code as it is today, I have by end of day to get it to work...yi=
kes the stress is unbearable, there are a million pagination scripts out th=
ere but I can't find any good alpha ones I can understand.
Ok what I have so far: the top part lists all the restaurant names, the bot=
tom part has the alpha pagination ...neither links to the results of a quer=
y...yet... Bit by bit right?

$sql =3D "SELECT DI=
STINCT name FROM restaurants WHERE name LIKE =
'$index_letter%' GROUP BY name D=
ESC"; =
$result =3D mysql_que=
ry($sql) or die(mysql_error()) ; =
$count =3D mysql_num_rows($result); =
=
while($row =3D mysql_fetch_array($result)) { =
=
=
$name=3D$row['name']; =
=
//prints out restaurant name with link ..... =
echo " me. "\"> $name\n
"; =
} =
=
} //al=
phabetical pagination links =
if (!isset($_GET['letter'])) {$letter =3D "A";} else {$=
letter =3D $_GET['letter'];} =
echo '

'; =
for ($i=3D65; $i<90; $i++) {=
if ($le=
tter!=3D chr($i)) {echo '';} =
echo chr($=
i)." "; =
if ($letter!=3D chr($i)) {echo '
';} =
} =
echo "

"; =
=
$query=3D"SELECT * FROM restaurants W=
HERE name LIKE '".$letter."%'"; =
=
=
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 17:30:12 von Ashley Sheridan

On Wednesday 15 July 2009 16:21:22 tedd wrote:
> At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
> >I am trying to make a page that displays a-z like a b c d e etc as links
> >then when you click open one it reloads itself and shows only the query
> >results that go with that letter...i'm not getting it....I get a page that
> >says ARRAY over and over...
> >
> >What I have so far:
>
> -snip-
>
> Why not have MySQL sort the data instead of using php?
>
> For example (from memory -- use with caution)
>
> SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1
>
> Then just change the offset to go up and down the list.
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com

You could do what Tedd suggested, but use MySQL to actually limit the results
it returns you by using a like clause, i.e. WHERE `somefield` LIKE 'a%'.

*ducks to avoid people throwing things at him. I know it's slow!*

--
Thanks,
Ash
http://www.ashleysheridan.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 17:45:52 von TedD

At 4:30 PM +0100 7/15/09, Ashley Sheridan wrote:
>On Wednesday 15 July 2009 16:21:22 tedd wrote:
>> At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
>> >I am trying to make a page that displays a-z like a b c d e etc as links
>> >then when you click open one it reloads itself and shows only the query
>> >results that go with that letter...i'm not getting it....I get a page that
>> >says ARRAY over and over...
>> >
>> >What I have so far:
>>
>> -snip-
>>
>> Why not have MySQL sort the data instead of using php?
>>
>> For example (from memory -- use with caution)
>>
>> SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1
>>
>> Then just change the offset to go up and down the list.
>>
>> Cheers,
>>
>> tedd
>> --
>> -------
>> http://sperling.com http://ancientstones.com http://earthstones.com
>
>You could do what Tedd suggested, but use MySQL to actually limit the results
>it returns you by using a like clause, i.e. WHERE `somefield` LIKE 'a%'.
>
>*ducks to avoid people throwing things at him. I know it's slow!*
>
>--
>Thanks,
>Ash


Ash:

My solution on this is simply to sort all the names and then pull
them out one by one depending upon where they appear in the sort. I
don't really see the need for LIKE to do this unless the user is
entering a guess. In such case, then you want to provide them with
your best fit.

Here's an example of both:

http://php1.net/a/edit-db-demo/index.php

The user can step through the database, which is initially sorted on
last name. If the user picks to sort on email, then the sort is done
as per email. In both cases, the data is stepped through sequentially
(Alphabetical pagination) by using an offset and limit combination.

However, if the user clicks on an alphabetical tab, then I use a LIKE
to place them (their pagination) at the position of that sort at that
character. That's where a LIKE would work well.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 17:46:53 von Andrew Ballard

On Wed, Jul 15, 2009 at 11:30 AM, Ashley
Sheridan wrote:
> On Wednesday 15 July 2009 16:21:22 tedd wrote:
>> At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
>> >I am trying to make a page that displays a-z like a b c d e etc as link=
s
>> >then when you click open one it reloads itself and shows only the query
>> >results that go with that letter...i'm not getting it....I get a page t=
hat
>> >says ARRAY over and over...
>> >
>> >What I have so far:
>>
>> -snip-
>>
>> Why not have MySQL sort the data instead of using php?
>>
>> For example (from memory -- use with caution)
>>
>> SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1
>>
>> Then just change the offset to go up and down the list.
>>
>> Cheers,
>>
>> tedd
>> --
>> -------
>> http://sperling.com  http://ancientstones.com  http://earthsto=
nes.com
>
> You could do what Tedd suggested, but use MySQL to actually limit the res=
ults
> it returns you by using a like clause, i.e. WHERE `somefield` LIKE 'a%'.
>
> *ducks to avoid people throwing things at him. I know it's slow!*
>
> --
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>

Why would that be slow? Using LIKE isn't always a bad thing. In this
case, the LIKE condition begins with a constant rather than a
wildcard, so it should perform well. It can even benefit from an index
on `somefield` if one exists.

I only see a couple issues with tedd's query:

1) As written, it only returns one row. To get it to return a list,
you'd have to call it repeatedly inside a for...loop where $offset
increments begins at some value and increments/decrements to an ending
value. But then he did say "from memory -- use with caution". The
general idea is correct.

2) It implements numeric pagination, which is usually based on a
fixed number of rows per page. The OP wanted alphabetical pagination
(like an address book) with each page containing all entries that
begin with the selected letter.


Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 17:48:25 von TedD

At 8:29 AM -0700 7/15/09, Miller, Terion wrote:
>
>Hi all thanks for all the suggestions, I really had no idea this was
>going to be so difficult..

I think you are making it more difficult than it has to be.

Please review what I said and try it out.

Cheers,

tedd



--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 17:57:08 von Ashley Sheridan

On Wednesday 15 July 2009 16:46:53 Andrew Ballard wrote:
> On Wed, Jul 15, 2009 at 11:30 AM, Ashley
>
> Sheridan wrote:
> > On Wednesday 15 July 2009 16:21:22 tedd wrote:
> >> At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
> >> >I am trying to make a page that displays a-z like a b c d e etc as
> >> > links then when you click open one it reloads itself and shows only
> >> > the query results that go with that letter...i'm not getting it....I
> >> > get a page that says ARRAY over and over...
> >> >
> >> >What I have so far:
> >>
> >> -snip-
> >>
> >> Why not have MySQL sort the data instead of using php?
> >>
> >> For example (from memory -- use with caution)
> >>
> >> SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1
> >>
> >> Then just change the offset to go up and down the list.
> >>
> >> Cheers,
> >>
> >> tedd
> >> --
> >> -------
> >> http://sperling.com  http://ancientstones.com  http://earths=
tones.com
> >
> > You could do what Tedd suggested, but use MySQL to actually limit the
> > results it returns you by using a like clause, i.e. WHERE `somefield`
> > LIKE 'a%'.
> >
> > *ducks to avoid people throwing things at him. I know it's slow!*
> >
> > --
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
>
> Why would that be slow? Using LIKE isn't always a bad thing. In this
> case, the LIKE condition begins with a constant rather than a
> wildcard, so it should perform well. It can even benefit from an index
> on `somefield` if one exists.
>
> I only see a couple issues with tedd's query:
>
> 1) As written, it only returns one row. To get it to return a list,
> you'd have to call it repeatedly inside a for...loop where $offset
> increments begins at some value and increments/decrements to an ending
> value. But then he did say "from memory -- use with caution". The
> general idea is correct.
>
> 2) It implements numeric pagination, which is usually based on a
> fixed number of rows per page. The OP wanted alphabetical pagination
> (like an address book) with each page containing all entries that
> begin with the selected letter.
>
>
> Andrew

I just had a query doing the same thing one time, and that did take it's ti=
me=20
(about 2-3 seconds) but it did have a few million records to look at, so I=
=20
can understand why it was slow!

And it was on MSSQL, with no indexes set up :( I nearly cried when I saw wh=
at=20
I was dealing with!

=2D-=20
Thanks,
Ash
http://www.ashleysheridan.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 18:03:25 von Martin Scotta

SET @letter :=3D 'B';
SELECT name FROM table WHERE SUBSTRING(name, 1) == @letter;
SELECT name FROM table WHERE name like concat(@letter, '%');

I don't know a faster way to do it

On Wed, Jul 15, 2009 at 12:57 PM, Ashley
Sheridan wrote:
> On Wednesday 15 July 2009 16:46:53 Andrew Ballard wrote:
>> On Wed, Jul 15, 2009 at 11:30 AM, Ashley
>>
>> Sheridan wrote:
>> > On Wednesday 15 July 2009 16:21:22 tedd wrote:
>> >> At 12:38 PM -0700 7/14/09, Miller, Terion wrote:
>> >> >I am trying to make a page that displays a-z like a b c d e etc as
>> >> > links then when you click open one it reloads itself and shows only
>> >> > the query results that go with that letter...i'm not getting it....=
I
>> >> > get a page that says ARRAY over and over...
>> >> >
>> >> >What I have so far:
>> >>
>> >> -snip-
>> >>
>> >> Why not have MySQL sort the data instead of using php?
>> >>
>> >> For example (from memory -- use with caution)
>> >>
>> >> SELECT name FROM restaurant ORDER BY name DESC LIMIT $offset, 1
>> >>
>> >> Then just change the offset to go up and down the list.
>> >>
>> >> Cheers,
>> >>
>> >> tedd
>> >> --
>> >> -------
>> >> http://sperling.com =A0http://ancientstones.com =A0http://earthstones=
..com
>> >
>> > You could do what Tedd suggested, but use MySQL to actually limit the
>> > results it returns you by using a like clause, i.e. WHERE `somefield`
>> > LIKE 'a%'.
>> >
>> > *ducks to avoid people throwing things at him. I know it's slow!*
>> >
>> > --
>> > Thanks,
>> > Ash
>> > http://www.ashleysheridan.co.uk
>>
>> Why would that be slow? Using LIKE isn't always a bad thing. In this
>> case, the LIKE condition begins with a constant rather than a
>> wildcard, so it should perform well. It can even benefit from an index
>> on `somefield` if one exists.
>>
>> I only see a couple issues with tedd's query:
>>
>> 1) As written, it only returns one row. To get it to return a list,
>> you'd have to call it repeatedly inside a for...loop where $offset
>> increments begins at some value and increments/decrements to an ending
>> value. But then he did say "from memory -- use with caution". The
>> general idea is correct.
>>
>> 2) =A0It implements numeric pagination, which is usually based on a
>> fixed number of rows per page. The OP wanted alphabetical pagination
>> (like an address book) with each page containing all entries that
>> begin with the selected letter.
>>
>>
>> Andrew
>
> I just had a query doing the same thing one time, and that did take it's =
time
> (about 2-3 seconds) but it did have a few million records to look at, so =
I
> can understand why it was slow!
>
> And it was on MSSQL, with no indexes set up :( I nearly cried when I saw =
what
> I was dealing with!
>
> --
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--=20
Martin Scotta

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination

am 15.07.2009 18:39:13 von tmiller

--snip----


How do I write the for each loop in here:

//alphabetical pagination links =
if (!isset($_GET['letter'])) {$letter =3D "A";} =
else {$letter =3D $_GET['letter'];} =
echo '

'; =
for ($i=3D65; $i<90; =
$i++) { =
if ($letter!=3D chr($i)) {echo ' >';} ech=
o chr($i)." "; =
if ($letter!=3D chr($i)) {echo '
'; =
=
----->>> for each letter pull out those=
restaurants names and reload the page .... =
=
=
=
=
} =
}

Or is that passed in the isset portion,

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Alphabetical pagination (RESOLVED)

am 16.07.2009 15:33:19 von tmiller

Here is what finally worked:

=3D isset($_GET['letter']) ? $_GET['letter'] : "A"; =
//alphabetical pagination links =
echo '

=
'; foreach(range('A'=
,'Z') as $c){ ($le=
tter == $c) =
? printf('%s ',$c) =
: printf(' ',$c,$c); =
} =
echo "

"; =
=
//Show all restaurants that start with $letter =
$sql =3D "SELECT * FROM restaurants WHE=
RE name LIKE '{$letter}%'"; =
$result =3D mysql_query($sql) or die(mysql_error()); =
while($row =3D mysql_fetch_assoc($=
result)){ printf('=

%s
%s
%s

r=3D#000 width=3D200>',$row['name'],$row['address'],$result['cviolatio=
ns']); } =
=
?>
Thanks again everyone!!


On 7/15/09 10:48 AM, "tedd" wrote:

At 8:29 AM -0700 7/15/09, Miller, Terion wrote:
>
>Hi all thanks for all the suggestions, I really had no idea this was
>going to be so difficult..

I think you are making it more difficult than it has to be.

Please review what I said and try it out.

Cheers,

tedd



--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Extract links from strings

am 21.09.2009 17:52:12 von Zechim

Hi there, i've the following strings:

$string1 = 'Lorem ipsum dolor http://site.com sit amet';
$string2 = 'Lorem ipsum dolor http://www.site.com/ sit amet';
$string3 = 'Lorem ipsum dolor http://www.site.net sit amet';

How can I extract the URL from these strings?
They can be [http:// + url] or [www. + url].

Zechim


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Extract links from strings

am 21.09.2009 18:56:43 von Paul M Foster

On Mon, Sep 21, 2009 at 12:52:12PM -0300, J=F4natas Zechim wrote:

> Hi there, i've the following strings:
>=20
> $string1 =3D 'Lorem ipsum dolor http://site.com sit amet';
> $string2 =3D 'Lorem ipsum dolor http://www.site.com/ sit amet';
> $string3 =3D 'Lorem ipsum dolor http://www.site.net sit amet';
>=20
> How can I extract the URL from these strings?
> They can be [http:// + url] or [www. + url].
>=20

Use the preg_match() function (see
http://us2.php.net/manual/en/function.preg-match.php ) and a good
regular expression from a place like http://www.regexlib.com/ .

Paul

--=20
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Extract links from strings

am 21.09.2009 19:45:09 von TedD

At 12:52 PM -0300 9/21/09, J=F4natas Zechim wrote:
>Hi there, i've the following strings:
>
>$string1 =3D 'Lorem ipsum dolor http://site.com sit amet';
>$string2 =3D 'Lorem ipsum dolor http://www.site.com/ sit amet';
>$string3 =3D 'Lorem ipsum dolor http://www.site.net sit amet';
>
>How can I extract the URL from these strings?
>They can be [http:// + url] or [www. + url].
>
>Zechim


Not tested:


$textString =3D 'orem ipsum dolor sit amet, consectetuer adipiscing
elit. Proin et urna. Duis quam. Suspendisse potenti. Etiam sem tortor,
ultricies nec, http://example.com imperdiet nec, tempus ac, purus.
Suspendisse id lectus. Nam vitae quam. Aliquam ligula nisl, vestibulum
vulputate, tempor nec, https://www.example.com tincidunt sit amet,
libero. Suspendisse a justo. Cum sociis natoque penatibus et.';

$url_regexp =
'<(?:(?:https?)://(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.=
])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0- 9]+[.][0-9]+[.][=
0-9]+[.][0-9]+)))(?::(?:(?:[0-9]*)))?(?:/(?:(?:(?:(?:(?:(?:[ a-zA-Z0-9\\-_.!~=
*\'():@&=3D+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a- zA-Z0-9\\-_.!~*\=
'():@&=3D+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(? :[a-zA-Z0-9\\-_.=
!~*\'():@&=3D+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[ a-zA-Z0-9\\-_.!~=
*\'():@&=3D+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?] (?:(?:(?:[;/?:@&=
=3D+$,a-zA-Z0-9\\-_.!~*\'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*) ))?))?)>';

$output =3D preg_replace($url_regexp, '', $textString);

print $output;
?>

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Extract links from strings

am 21.09.2009 20:06:34 von Mattias Thorslund

Jônatas Zechim wrote:
> Hi there, i've the following strings:
>
> $string1 = 'Lorem ipsum dolor http://site.com sit amet';
> $string2 = 'Lorem ipsum dolor http://www.site.com/ sit amet';
> $string3 = 'Lorem ipsum dolor http://www.site.net sit amet';
>
> How can I extract the URL from these strings?
> They can be [http:// + url] or [www. + url].
>
> Zechim

Simple:

function RemoveLorem($string)
{
return str_replace(array('Lorem ipsum dolor ', ' sit amet'), '',
$string);
}

$url1 = RemoveLorem($string1);
$url2 = RemoveLorem($string2);
$url3 = RemoveLorem($string3);

Cheers :-)

Mattias

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Extract links from strings

am 21.09.2009 20:06:58 von Ashley Sheridan

On Mon, 2009-09-21 at 11:06 -0700, Mattias Thorslund wrote:
> Jônatas Zechim wrote:
> > Hi there, i've the following strings:
> >
> > $string1 =3D 'Lorem ipsum dolor http://site.com sit amet';
> > $string2 =3D 'Lorem ipsum dolor http://www.site.com/ sit amet';
> > $string3 =3D 'Lorem ipsum dolor http://www.site.net sit amet';
> >
> > How can I extract the URL from these strings?
> > They can be [http:// + url] or [www. + url].
> >
> > Zechim
>=20
> Simple:
>=20
> function RemoveLorem($string)
> {
> return str_replace(array('Lorem ipsum dolor ', ' sit amet'), '',=20
> $string);
> }
>=20
> $url1 =3D RemoveLorem($string1);
> $url2 =3D RemoveLorem($string2);
> $url3 =3D RemoveLorem($string3);
>=20
> Cheers :-)
>=20
> Mattias
>=20
Erm, I think the Lorem Ipsum was just filler text in this example, and
may not actually occur in the final content ;)


Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RES: Extract links from strings

am 21.09.2009 22:12:42 von Zechim

I don't think so, but I've found this (from PT-BR LIST):

$string =3D 'Lorem ipsum dolor http://site.com sit amet lorem =
www.google.com
';

preg_match_all('!(?:http://|www)[^ ]*!',$string,$links);

print_r($links);

Zechim

-----Mensagem original-----
De: Mattias Thorslund [mailto:mattias@thorslund.us]=20
Enviada em: segunda-feira, 21 de setembro de 2009 15:07
Para: 'PHP-General List'
Assunto: Re: [PHP] Extract links from strings

J=F4natas Zechim wrote:
> Hi there, i've the following strings:
>
> $string1 =3D 'Lorem ipsum dolor http://site.com sit amet';
> $string2 =3D 'Lorem ipsum dolor http://www.site.com/ sit amet';
> $string3 =3D 'Lorem ipsum dolor http://www.site.net sit amet';
>
> How can I extract the URL from these strings?
> They can be [http:// + url] or [www. + url].
>
> Zechim

Simple:

function RemoveLorem($string)
{
return str_replace(array('Lorem ipsum dolor ', ' sit amet'), '',=20
$string);
}

$url1 =3D RemoveLorem($string1);
$url2 =3D RemoveLorem($string2);
$url3 =3D RemoveLorem($string3);

Cheers :-)

Mattias

--=20
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Extract links from strings

am 22.09.2009 00:26:45 von List Manager

Jônatas Zechim wrote:
> Hi there, i've the following strings:
>
> $string1 = 'Lorem ipsum dolor http://site.com sit amet';
> $string2 = 'Lorem ipsum dolor http://www.site.com/ sit amet';
> $string3 = 'Lorem ipsum dolor http://www.site.net sit amet';
>
> How can I extract the URL from these strings?
> They can be [http:// + url] or [www. + url].
>
> Zechim
>
>

Something like this should work for you.

<?php<br /> <br /> $urls[] = 'Lorem ipsum dolor http://site.com sit amet';<br /> $urls[] = 'Lorem ipsum dolor https://www.site.com/ sit amet';<br /> $urls[] = 'Lorem ipsum dolor www.site1.net sit amet';<br /> $urls[] = 'Lorem ipsum dolor www site2.net sit amet';<br /> <br /> foreach ( $urls AS $url ) {<br /> if ( preg_match('%((https?://|www\.)[^\s]+)%', $url, $m) ) {<br /> print_r($m);<br /> }<br /> }<br /> <br /> ?><br /> <br /> <br /> -- <br /> PHP General Mailing List (http://www.php.net/)<br /> To unsubscribe, visit: http://www.php.net/unsub.php</p> </article> <article> <h2>Re: Extract links from strings</h2><span>am 22.09.2009 01:20:06 von List Manager</span> <p>Jim Lucas wrote:<br /> > Jônatas Zechim wrote:<br /> >> Hi there, i've the following strings:<br /> >><br /> >> $string1 = 'Lorem ipsum dolor http://site.com sit amet';<br /> >> $string2 = 'Lorem ipsum dolor http://www.site.com/ sit amet';<br /> >> $string3 = 'Lorem ipsum dolor http://www.site.net sit amet';<br /> >><br /> >> How can I extract the URL from these strings?<br /> >> They can be [http:// + url] or [www. + url].<br /> >><br /> >> Zechim<br /> >><br /> >><br /> > <br /> > Something like this should work for you.<br /> > <br /> > <plaintext><?php<br /> > <br /> > $urls[] = 'Lorem ipsum dolor http://site.com sit amet';<br /> > $urls[] = 'Lorem ipsum dolor https://www.site.com/ sit amet';<br /> > $urls[] = 'Lorem ipsum dolor www.site1.net sit amet';<br /> > $urls[] = 'Lorem ipsum dolor www site2.net sit amet';<br /> > <br /> > foreach ( $urls AS $url ) {<br /> > if ( preg_match('%((https?://|www\.)[^\s]+)%', $url, $m) ) {<br /> > print_r($m);<br /> > }<br /> > }<br /> > <br /> > ?><br /> > <br /> <br /> Actually, try this. It seems to work a little better.<br /> <br /> <plaintext><?php<br /> <br /> $urls[] = 'Lorem ipsum dolor http://site.com sit amet';<br /> $urls[] = 'Lorem ipsum dolor https://www.site.com/ or http://www.site2.com/';<br /> $urls[] = 'Lorem ipsum dolor www.site1.net sit amet';<br /> $urls[] = 'Lorem ipsum dolor www site2.net sit amet';<br /> <br /> foreach ( $urls AS $url ) {<br /> if ( preg_match_all( '%(https?://[^\s]+|www\.[^\s]+)%',<br /> $url,<br /> $m,<br /> (PREG_SET_ORDER ^ PREG_OFFSET_CAPTURE)<br /> ) ) {<br /> print_r($m);<br /> }<br /> }<br /> <br /> ?><br /> <br /> <br /> -- <br /> PHP General Mailing List (http://www.php.net/)<br /> To unsubscribe, visit: http://www.php.net/unsub.php</p> </article> <article> <h2>Re: Extract links from strings</h2><span>am 23.09.2009 17:02:27 von Philip Thompson</span> <p>On Sep 21, 2009, at 6:20 PM, Jim Lucas wrote:<br /> <br /> > Jim Lucas wrote:<br /> >> J=F4natas Zechim wrote:<br /> >>> Hi there, i've the following strings:<br /> >>><br /> >>> $string1 =3D 'Lorem ipsum dolor http://site.com sit amet';<br /> >>> $string2 =3D 'Lorem ipsum dolor http://www.site.com/ sit amet';<br /> >>> $string3 =3D 'Lorem ipsum dolor http://www.site.net sit amet';<br /> >>><br /> >>> How can I extract the URL from these strings?<br /> >>> They can be [http:// + url] or [www. + url].<br /> >>><br /> >>> Zechim<br /> >>><br /> >>><br /> >><br /> >> Something like this should work for you.<br /> >><br /> >> <plaintext><?php<br /> >><br /> >> $urls[] =3D 'Lorem ipsum dolor http://site.com sit amet';<br /> >> $urls[] =3D 'Lorem ipsum dolor https://www.site.com/ sit amet';<br /> >> $urls[] =3D 'Lorem ipsum dolor www.site1.net sit amet';<br /> >> $urls[] =3D 'Lorem ipsum dolor www site2.net sit amet';<br /> >><br /> >> foreach ( $urls AS $url ) {<br /> >> if ( preg_match('%((https?://|www\.)[^\s]+)%', $url, $m) ) {<br /> >> print_r($m);<br /> >> }<br /> >> }<br /> >><br /> >> ?><br /> >><br /> ><br /> > Actually, try this. It seems to work a little better.<br /> ><br /> > <plaintext><?php<br /> ><br /> > $urls[] =3D 'Lorem ipsum dolor http://site.com sit amet';<br /> > $urls[] =3D 'Lorem ipsum dolor https://www.site.com/ or =<br /> http://www.site2.com/'=20<br /> > ;<br /> > $urls[] =3D 'Lorem ipsum dolor www.site1.net sit amet';<br /> > $urls[] =3D 'Lorem ipsum dolor www site2.net sit amet';<br /> ><br /> > foreach ( $urls AS $url ) {<br /> > if ( preg_match_all( '%(https?://[^\s]+|www\.[^\s]+)%',<br /> > $url,<br /> > $m,<br /> > (PREG_SET_ORDER ^ PREG_OFFSET_CAPTURE)<br /> > ) ) {<br /> > print_r($m);<br /> > }<br /> > }<br /> ><br /> > ?><br /> <br /> What if the sub domain was not 'www'?<br /> <br /> http://no-www.org/<br /> <br /> Cheers,<br /> ~Philip<br /> <br /> <br /> -- <br /> PHP General Mailing List (http://www.php.net/)<br /> To unsubscribe, visit: http://www.php.net/unsub.php</p> </article> <article> <h2>Re: Extract links from strings</h2><span>am 23.09.2009 18:58:56 von List Manager</span> <p>Philip Thompson wrote:<br /> > On Sep 21, 2009, at 6:20 PM, Jim Lucas wrote:<br /> > <br /> >> Jim Lucas wrote:<br /> >>> Jônatas Zechim wrote:<br /> >>>> Hi there, i've the following strings:<br /> >>>><br /> >>>> $string1 = 'Lorem ipsum dolor http://site.com sit amet';<br /> >>>> $string2 = 'Lorem ipsum dolor http://www.site.com/ sit amet';<br /> >>>> $string3 = 'Lorem ipsum dolor http://www.site.net sit amet';<br /> >>>><br /> >>>> How can I extract the URL from these strings?<br /> >>>> They can be [http:// + url] or [www. + url].<br /> >>>><br /> >>>> Zechim<br /> >>>><br /> >>>><br /> >>><br /> >>> Something like this should work for you.<br /> >>><br /> >>> <plaintext><?php<br /> >>><br /> >>> $urls[] = 'Lorem ipsum dolor http://site.com sit amet';<br /> >>> $urls[] = 'Lorem ipsum dolor https://www.site.com/ sit amet';<br /> >>> $urls[] = 'Lorem ipsum dolor www.site1.net sit amet';<br /> >>> $urls[] = 'Lorem ipsum dolor www site2.net sit amet';<br /> >>><br /> >>> foreach ( $urls AS $url ) {<br /> >>> if ( preg_match('%((https?://|www\.)[^\s]+)%', $url, $m) ) {<br /> >>> print_r($m);<br /> >>> }<br /> >>> }<br /> >>><br /> >>> ?><br /> >>><br /> >><br /> >> Actually, try this. It seems to work a little better.<br /> >><br /> >> <plaintext><?php<br /> >><br /> >> $urls[] = 'Lorem ipsum dolor http://site.com sit amet';<br /> >> $urls[] = 'Lorem ipsum dolor https://www.site.com/ or<br /> >> http://www.site2.com/';<br /> >> $urls[] = 'Lorem ipsum dolor www.site1.net sit amet';<br /> >> $urls[] = 'Lorem ipsum dolor www site2.net sit amet';<br /> >><br /> >> foreach ( $urls AS $url ) {<br /> >> if ( preg_match_all( '%(https?://[^\s]+|www\.[^\s]+)%',<br /> >> $url,<br /> >> $m,<br /> >> (PREG_SET_ORDER ^ PREG_OFFSET_CAPTURE)<br /> >> ) ) {<br /> >> print_r($m);<br /> >> }<br /> >> }<br /> >><br /> >> ?><br /> > <br /> > What if the sub domain was not 'www'?<br /> > <br /> > http://no-www.org/<br /> > <br /> <br /> Well, if it had the http:// at the beginning, then it would be found.<br /> <br /> but, somedomain.no-www.org would not work.<br /> <br /> But, if they only had no-www.org, it would only find www.org<br /> <br /> So, I guess it would need to be looking at the characters before the www\. part<br /> to include them in the url also<br /> <br /> This should work. Note: the [^\s]+ placed before the www\. portion.<br /> <br /> if ( preg_match_all( '%(https?://[^\s]+|[^\/\s]+www\.[^\s]+)%',<br /> <br /> This should catch example.www.org and no-www.org now.<br /> <br /> You could get into the business of trying to match the TLD, but that would be a<br /> PITA to keep updated.<br /> <br /> <br /> > Cheers,<br /> > ~Philip<br /> > <br /> > <br /> <br /> <br /> <br /> -- <br /> PHP General Mailing List (http://www.php.net/)<br /> To unsubscribe, visit: http://www.php.net/unsub.php</p> </article> <footer> <a href="/">Index</a> | <a href="/impressum.php">Impressum</a> | <a href="/datenschutz.php">Datenschutz</a> | <a href="https://www.xodox.de/">XODOX</a> </footer> </main> </body> </html>